{% load static %}
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <!-- 在 <head> 中添加清除缓存的 meta 标签 -->
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <title>{{ title }}</title>
    <link rel="stylesheet" href="{% static 'css/index.css' %}">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>

    <div class="banner">
        <div class="logo">
            <div class="logo-icon">RSS</div>
            <div class="logo-text"><a href="/">博客园</a></div>
        </div>
        <nav class="nav">
            <a href="chat_page/" class="nav-item">AI聊天</a>
            <a href="https://news.cctv.com/" class="nav-item">新闻</a>
            <a href="#" class="nav-item">关注</a>
            <a href="#" class="nav-item">关于</a>
            <a href="#" class="nav-item">更多</a>

        </nav>
        <div class="search-bar">
            <input type="text" id="search" value="{{ key_word }}" class="search-input" placeholder="代码改变世界">
        </div>
        <div class="login" style="color:white;margin-left:20px">
            {% if username %}
            <span>欢迎：<a href="/user_center">{{ username }}</a></span>&nbsp;&nbsp;&nbsp;&nbsp;
            <span><a style="text-decoration: none;color:inherit;" href="/logout">退出</a></span>
            {% else %}
            <span><a style="text-decoration: none;color:inherit;" href="/login">登录</a></span>&nbsp;&nbsp;&nbsp;&nbsp;
            <span><a style="text-decoration: none;color:inherit;" href="/register">注册</a></span>
            {% endif%}

        </div>
    </div>
    <div class="container">
        <div class="main-content">
            {% if articles %}
            {% for article in articles %}
            <div class="article-list">
                <a href="/detail/{{article.id}}" class="article-title">{{ article.title }}</a>
                <div class="article-meta">{{article.publish_time }}</div>
                <div class="article-excerpt">
                   {{ article.description }}
                </div>
            </div>
            {% endfor %}
            {% else %}
                <div style="color:white;font-size:18px">没有内容</div>
            {% endif%}

        </div>


    </div>
</body>
</html>
<script>
$(document).ready(function() {
    $('#search').on('keydown', function(e) {
        // 获取按下的键的键码
        var key = e.which || e.keyCode;

        // 检查是否按下的是 Enter 键（键码 13）
        if (key === 13) {
            e.preventDefault(); // 阻止默认行为（如果需要）
            // 在这里编写你希望在按下 Enter 时执行的代码
            console.log('Enter 键被按下！');

            // 获取输入框的内容
            let key_word = $("#search").val()
            location.href = "/search?q=" + key_word
        }
    });
});


</script>